package cn.gs.web;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;

import cn.gs.domain.Customer;
import cn.gs.domain.LinkMan;

import cn.gs.service.SelectLinkManService;

@Component(value = "selectLinkManAction")
@Scope("prototype")
public class SelectLinkManAction extends ActionSupport implements ModelDriven<LinkMan> {
	private LinkMan linkman = new LinkMan();
	private Customer customer = new Customer();
	@Resource(name = "selectLinkManService")
	private SelectLinkManService selectLinkManService;
	private List<LinkMan> list;
	private String pageCount;
	private String page;
	private String pCount;
	private String cname;

	public String allsel() {
		if (page == null) {
			page = "1";
		}
		int i = Integer.valueOf(page);
		String a1 = linkman.getLkm_name();
		customer.setCust_name(cname);
		String b1=customer.getCust_name();
		try {
			list = selectLinkManService.selectLinkMan(a1, b1, i);
			List l = selectLinkManService.selectPageCount(linkman.getLkm_name(), b1);
			
			pageCount = String.valueOf(l.get(0));
			int a = Integer.valueOf(pageCount);
			int b = 0;
			if (a % 3 == 0) {
				b = a / 3;
			} else {
				b = a / 3 + 1;
			}
			pCount = String.valueOf(b);
			ActionContext.getContext().put("pCount", pCount);
			ActionContext.getContext().put("pageCount", pageCount);
			ActionContext.getContext().put("list", list);
			return "selSuc";

		} catch (Exception e) {
			e.printStackTrace();
			return "selDef";
		}

	}

	public LinkMan getModel() {
		// TODO Auto-generated method stub
		return linkman;
	}

	public SelectLinkManService getSelectLinkManService() {
		return selectLinkManService;
	}

	public void setSelectLinkManService(SelectLinkManService selectLinkManService) {
		this.selectLinkManService = selectLinkManService;
	}

	public List<LinkMan> getList() {
		return list;
	}

	public void setList(List<LinkMan> list) {
		this.list = list;
	}

	public String getPageCount() {
		return pageCount;
	}

	public void setPageCount(String pageCount) {
		this.pageCount = pageCount;
	}

	public String getPage() {
		return page;
	}

	public void setPage(String page) {
		this.page = page;
	}

	public String getpCount() {
		return pCount;
	}

	public void setpCount(String pCount) {
		this.pCount = pCount;
	}

	public Customer getCustomer() {
		return customer;
	}

	public void setCustomer(Customer customer) {
		this.customer = customer;
	}

	public String getCname() {
		return cname;
	}

	public void setCname(String cname) {
		this.cname = cname;
	}

}
